package org.lora.exception.handle;

/**
 * <p>
 * Title:ErrorContext
 * </p>
 * <p>
 * Desription:
 * </p>
 * Create Time:2016年7月11日 下午2:27:57
 * 
 * @author Bladnir@outlook.com
 *         <p>
 *         History:
 *         </p>
 *         2016年7月11日 Bladnir Create</br>
 */
public class ErrorContext {
	
	public static final String CANT_FIND_CLASS = "cant find class";

	private static final String LINE_SEPARATOR = System.getProperty("line.separator", "\n");

	private String className;

	private String methodName;

	private String fieldName;

	private String fieldType;

	private String message;

	private String url;

	private String[] parameterTypeArray;

	/**
	 * @param className
	 * @return
	 */
	public ErrorContext className(String className) {
		this.className = className;
		return this;
	}

	/**
	 * @param methodName
	 * @return
	 */
	public ErrorContext methodName(String methodName) {
		this.methodName = methodName;
		return this;
	}

	/**
	 * @param fieldName
	 * @return
	 */
	public ErrorContext fieldName(String fieldName) {
		this.fieldName = fieldName;
		return this;
	}

	/**
	 * @param fieldType
	 * @return
	 */
	public ErrorContext fieldType(String fieldType) {
		this.fieldType = fieldType;
		return this;
	}

	/**
	 * @param message
	 * @return
	 */
	public ErrorContext message(String message) {
		this.message = message;
		return this;
	}

	/**
	 * @param url
	 * @return
	 */
	public ErrorContext url(String url) {
		this.url = url;
		return this;
	}

	/**
	 * @param parameterTypeArray
	 * @return
	 */
	public ErrorContext parameterTypeArray(String[] parameterTypeArray) {
		this.parameterTypeArray = parameterTypeArray;
		return this;
	}

	@Override
	public String toString() {
		StringBuilder description = new StringBuilder();

		if (this.message != null) {
			description.append(LINE_SEPARATOR);
			description.append("### ");
			description.append(this.message);
		}

		if (this.className != null) {
			description.append(LINE_SEPARATOR);
			description.append("className ");
			description.append(this.className);
		}

		if (this.fieldType != null) {
			description.append(LINE_SEPARATOR);
			description.append("fieldType ");
			description.append(this.fieldType);
		}

		if (this.fieldName != null) {
			description.append(LINE_SEPARATOR);
			description.append("fieldName ");
			description.append(this.fieldName);
		}

		if (this.methodName != null) {
			description.append(LINE_SEPARATOR);
			description.append("methodName ");
			description.append(this.methodName);
		}

		if (this.url != null) {
			description.append(LINE_SEPARATOR);
			description.append("url ");
			description.append(this.url);
		}

		if (parameterTypeArray != null && parameterTypeArray.length > 0) {
			description.append(LINE_SEPARATOR);
			for (String parameterType : parameterTypeArray) {
				description.append(parameterType + " ");
			}
		}

		return description.toString();
	}

}
